package com.heiwa.email163.impl;

import com.heiwa.email163.Email163Configuration;
import com.heiwa.email163.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;


@Component
public class IEmailService implements EmailService {
    Logger logger = Logger.getLogger(IEmailService.class.getName());
    @Autowired
    private JavaMailSender mailSender;

    @Autowired
    private Email163Configuration email163Configuration;

    /**
     * 发送文本邮件
     *
     * @param recipient 收件人
     * @param subject   主题
     * @param content   内容
     */
    @Override
    public void sendSimpleMail(String recipient, String subject, String content) {
        //创建SimpleMailMessage对象
        SimpleMailMessage message = new SimpleMailMessage();
        //邮件发送人
        message.setFrom(email163Configuration.getUsername());
        //邮件接收人
        message.setTo(recipient);
        //邮件主题
        message.setSubject(subject);
        //邮件内容
        message.setText(content);
        logger.info("读取到的message内容: "+message.getFrom()+" "+message.getText() + " "+message.getSubject() + " "+message.getTo().toString());
        logger.info("mailSender : " + mailSender.toString());
        //发送邮件
        mailSender.send(message);
    }

    /**
     * 发送HTML邮件
     *
     * @param recipient 收件人
     * @param subject   主题
     * @param content   内容
     */
    @Override
    public void sendHtmlMail(String recipient, String subject, String content) {
        System.out.println("读取到的message.email内容: "+email163Configuration.toString());
    }

    /**
     * 发送带附件的邮件
     *
     * @param recipient 收件人
     * @param subject   主题
     * @param content   内容
     * @param filePath  附件
     */
    @Override
    public void sendAttachmentsMail(String recipient, String subject, String content, String filePath) {

    }

    /**
     * 发送模板邮件
     *
     * @param recipient 收件人
     * @param subject   主题
     * @param fileName  邮件模板文件名称
     * @param model     邮件数据载体
     */
    @Override
    public void sendModelMail(String recipient, String subject, String fileName, Object model) {

    }
}
